package com.yupi.yuso.datasource;

import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @program: yuso-backend-public
 * @ClassName: MyDataSourceRegistry
 * @description: 数据源仓库
 * @author: AlanMa
 * @create: 2024-02-29 14:46
 */
@Component
public class MyDataSourceRegistry implements ApplicationContextAware {

    private Map<String, DataSource> map ;


    private List<DataSource> dataSourceList;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        map = applicationContext.getBeansOfType(DataSource.class);
        dataSourceList = new ArrayList<>(map.values());
    }


    public DataSource getDataSource(String type) {
        return map.get(type);
    }

    public List<DataSource> getAll(){
        return dataSourceList;
    }

}
